package com.smartmedical.patient.sickcricle.controller;

import com.smartmedical.common.core.domain.HealthR;
import com.smartmedical.patient.sickcricle.dto.SickCircleDto;
import com.smartmedical.patient.sickcricle.service.SickCircleService;
import com.smartmedical.patient.sickcricle.vo.SickCircleCommentVo;
import com.smartmedical.patient.sickcricle.vo.SickCircleDetailVo;
import com.smartmedical.patient.sickcricle.vo.SickCirclePublishVo;
import com.smartmedical.patient.sickcricle.vo.SickCircleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.github.pagehelper.page.PageMethod.startPage;

@RestController
@RequestMapping("user/sickCircle/v1")
public class SickCircleController {

    @Autowired
    private SickCircleService sickCircleService;

    /**
     * 病友圈列表展示
     */
    @GetMapping("/findSickCircleList")
    public HealthR<List<SickCircleVo>> findSickCircleList(@RequestParam Integer departmentId,
                                                          @RequestParam Integer page,
                                                          @RequestParam Integer count) {
        startPage(page, count);
        return sickCircleService.findSickCircleList(departmentId);

    }


    /**
     * 查询病友圈详情
     */
    @GetMapping("/findSickCircleInfo")
    public HealthR<SickCircleDetailVo> findSickCircleInfo(@RequestParam Integer sickCircleId) {
        SickCircleDetailVo sickCircleInfo = sickCircleService.findSickCircleInfo(sickCircleId);
        return HealthR.ok(sickCircleInfo);
    }


    /**
     * 根据关键字查询病友圈
     */
    @GetMapping("/searchSickCircle")
    public HealthR<List<SickCircleVo>> searchSickCircle(@RequestParam String keyword) {
        return sickCircleService.searchSickCircle(keyword);
    }


    /**
     * 查询评论列表
     */
    @GetMapping("/findSickCircleCommentList")
    public HealthR<List<SickCircleCommentVo>> findSickCircleCommentList(
            @RequestHeader(value = "userId",required = false) Integer userId,
            @RequestHeader(value = "Sessionid",required = false) String sessionId,
            @RequestParam Integer sickCircleId,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "count", defaultValue = "5") Integer count) {
        startPage(page, count);
        return sickCircleService.findSickCircleCommentList(sickCircleId);
    }

    /**
     * 查看病友的病友圈发帖列表
     */
    @GetMapping("/findPatientSickCircleList")
    public HealthR<List<SickCirclePublishVo>> findPatientSickCircleList(
            @RequestHeader Integer patientUserId,
            @RequestParam Integer page,
            @RequestParam Integer count) {

        return sickCircleService.findPatientSickCircleList(patientUserId, page, count);

    }





}
